package com.wifi.user.service;


import com.wifi.user.dao.UserDao;
import com.wifi.user.dao.UserDaoImp;
import com.wifi.user.entity.User;

import java.sql.SQLException;
import java.util.List;

public class UserServiceImpl implements UserService {
UserDao userDao=new UserDaoImp();
    @Override
    public Object login(User user, String name, String pwd) {
        try {
            return userDao.login(user,name,pwd);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer setLoginDate(Integer id) {
        try {
            return userDao.updateLastLoginTime(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public Object getUserByID(String id) {
        try {
            return userDao.selectUserById(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return null;
    }

    @Override
    public Integer updatePwd(String pwd, int id) {
        try {
            return userDao.updatePwd(pwd,id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return null;
    }

    @Override
    public List<Object> queryAll() {
        try {
            return userDao.selectUser();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return null;
    }

    @Override
    public Long addUser(User user) {
        try {
            return userDao.insertUser(user);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return (long)0;
    }

    @Override
    public Integer changeStatus(Integer idi, Integer integer) {
        try {
            return userDao.updateStatus(idi,integer);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return 0;
    }

    @Override
    public Integer delUser(Integer idi) {
        try {
            return userDao.updateDelu(idi);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return 0;
    }

    @Override
    public Object queryBynName(User user, String username) {
        try {
            return userDao.selectByName(user,username);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return null;
    }

    @Override
    public Integer editUser(User user) {
        try {
            return userDao.updateUser(user);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return 0;
    }

    @Override
    public Integer forgetPwd(String id, String unm, String pwdMD5) {
        try {
            return userDao.updatePwd(id,unm,pwdMD5);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }return 0;
    }
}
